/*
* ExpressionFactoryEnthalpy.java
* Created on  202015/6/10 19:42
* 版本       修改时间          作者      修改内容
* V1.0.1    202015/6/10       panzhuowen    初始版本
*
*/

package com.infitecs.eyas.util;

import fr.expression4j.core.Catalog;
import fr.expression4j.core.Expression;
import fr.expression4j.core.ExpressionModel;
import fr.expression4j.core.Parameters;
import fr.expression4j.core.exception.EvalException;
import fr.expression4j.core.exception.ModelException;
import fr.expression4j.core.exception.ParsingException;
import fr.expression4j.core.impl.CatalogImpl;
import fr.expression4j.core.impl.ExpressionImpl;
import fr.expression4j.core.impl.OptimizedExpression;
import fr.expression4j.core.impl.ParametersImpl;
import fr.expression4j.factory.ExpressionModelFactory;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

/**
 * 类的描述信息
 *
 * @author panzhuowen
 * @version 1.0.1
 */
public class ExpressionFactoryEnthalpy {
    private static Map catalogMap;
    private static Catalog generalCatalog;

    public ExpressionFactoryEnthalpy() {
    }

    public static Expression createExpression(String var0) throws ParsingException {
        try {
            ExpressionModel var1 = ExpressionModelFactory.getDefaultExpressionModel();
            return createExpression(var0, generalCatalog, var1);
        } catch (ModelException var2) {
            throw new ParsingException("Cannot create default ExpressionModel.", var2);
        }
    }

    public static Expression createExpression(String var0, Catalog var1) throws ParsingException {
        try {
            ExpressionModel var2 = ExpressionModelFactory.getDefaultExpressionModel();
            return createExpression(var0, var1, var2);
        } catch (ModelException var3) {
            throw new ParsingException("Cannot create default ExpressionModel.", var3);
        }
    }

    public static Expression createExpression(String var0, Catalog var1, ExpressionModel var2) throws ParsingException {
        ExpressionImpl var3 = new ExpressionImpl();
        var3.parse(var0, var1, var2);
        var1.addExpression(var3);
        return var3;
    }

    public static Catalog createCatalog(String var0) {
        Object var1 = (Catalog)catalogMap.get(var0);
        if(var1 == null) {
            var1 = new CatalogImpl(var0);
            catalogMap.put(var0, var1);
        }

        return (Catalog)var1;
    }

    public static Parameters createParameters() {
        return new ParametersImpl();
    }

    public static Catalog getCatalog() {
        return generalCatalog;
    }

    public static Catalog getCatalog(String var0) {
        return (Catalog)catalogMap.get(var0);
    }

    public static List getCatalogList() {
        Vector var0 = new Vector(5);
        Iterator var1 = catalogMap.keySet().iterator();

        while(var1.hasNext()) {
            var0.add(var1.next());
        }

        return var0;
    }

    public static Expression optimizeExpression(Expression var0) {
        if(var0 instanceof ExpressionImpl) {
            try {
                return new OptimizedExpression((ExpressionImpl)var0);
            } catch (EvalException var2) {
                return var0;
            }
        } else {
            return var0;
        }
    }

    static {
        catalogMap = new HashMap(10);
        generalCatalog = new CatalogImpl("general");
        catalogMap.put("general", generalCatalog);
    }
}
